var searchparam;

/**
 *model 
 */    
    Ext.define('model_zxz', {
         extend: 'Ext.data.Model',
         fields: [
             {name: 'jyz_mc', type: 'string'},
             {name: 'jyz_sh',  type: 'string'},
             {name: 'sbyf',  type: 'string'},
             {name: 'yp_93',  type: 'int'},
             {name: 'yp_97',  type: 'int'},
             {name: 'yp_0',  type: 'int'},
             {name: 'yp_other',  type: 'int'},
             {name: 'yp_sum',   type:'int'}
         ]
     });

/**
 *store 
 */     
     var store_zxz=Ext.create('Ext.data.Store', {
        model: 'model_zxz',
        autoDestroy: true,
        autoLoad: false,
        pageSize:100,
        listeners:{
            beforeload:function(store,operation,eOpts){//添加事件在获取数据前触发
                if(searchparam){
                    store.proxy.extraParams=searchparam;
                }
            }
        },
        proxy: {
            type: 'ajax',
            url: 'getPtzListAction.action',
            reader: {
                type: 'json',
                root: 'items',
                totalProperty:'totalCount'
            }
        }
     });

 /**
  *grid表格头 
  */    
     var col_zxz=[
        {xtype:'rownumberer',width:40}, 
        {text:'普通加油站名称',width:150,dataIndex:'jyz_mc',menuDisabled:true,sortable:false},
        {text:'普通加油站税号',width:100,dataIndex:'jyz_sh',menuDisabled:true,sortable:false},
        {text:'申报月份',width:100,dataIndex:'sbyf',menuDisabled:true,sortable:false},
        {text:'汽油93#(升)',width:100,dataIndex:'yp_93',menuDisabled:true,sortable:false},
        {text:'汽油97#(升)',width:100,dataIndex:'yp_97',menuDisabled:true,sortable:false},
        {text:'柴油0#(升)',width:100,dataIndex:'yp_0',menuDisabled:true,sortable:false},
        {text:'其他(升)',width:100,dataIndex:'yp_other',menuDisabled:true,sortable:false},
        {text:'总计(升)',width:100,dataIndex:'yp_sum',menuDisabled:true,sortable:false} 
     ];

     Ext.onReady(function(){
         Ext.create('Ext.panel.Panel',{
             id:'main-panel',
             width:Ext.getBody().getWidth()-20,
             renderTo:Ext.getBody(),
             layout:{
                 type:'vbox',
                 align: 'stretch'
             },
             items:[{
                        xtype: 'grid',
                        id:'grid_zxz',
                        title:'普通加油站汇总数据报表',
                        height:650,
                        //selModel: Ext.create('Ext.selection.CheckboxModel', { mode: "SIMPLE" }),
                        columns: col_zxz,            
                        store: store_zxz,
                        dockedItems:[
                            {
                                xtype: 'toolbar',
                                items:[{
                                    xtype:'button',
                                    text:'查询',
                                    margin:'10 10 0 10',
                                    width:120,
                                    handler:function(){
                                            showSearchDlg();
                                    }
                                }]
                            },{
                                xtype: 'pagingtoolbar',
                                store: store_zxz,   
                                dock: 'bottom',
                                displayInfo: true
                            }
                        ], 
                        flex: 1  
             }]
         });
     });

     function showSearchDlg(){
         var dlg=Ext.create('Ext.window.Window',{
             title:'查询条件',
             width:350,
             height:200,
             layout:'fit',
             resize:false,
             modal:true,
             items:[
                    Ext.create('Ext.form.Panel',{
                        bodyPadding:5,
                        //width:700,
                        layout:'anchor',
                        items:[
                            {
                                xtype:'treepicker',
                                fieldLabel:'中心站列表',
                                name: 'jyz_bh',
                                valueField : 'id',
                                displayField : 'text',
                                store : new Ext.data.TreeStore({
                                    root : {
                                        expanded : true
                                    },
                                    proxy : {
                                        type : 'ajax',
                                        url : 'getAllZXGasListAction.action'
                                    },
                                    autoLoad : true
                                }),
                                labelWidth:80,
                                width:300,
                                allowBlank: false
                            },{
                                xtype:'monthcombobox',
                                fieldLabel:'申报月份',
                                name: 'sbyf',
                                labelWidth:80,
                                width:300
                            }
                     ],
                     buttons:[{
                            text:'提交',
                            handler:function(){
                                var f=this.up('form').getForm();
                                if(f.isValid()){
                                    searchparam=this.up('form').getForm().getValues();
                                    store_zxz.loadPage(1);
                                    dlg.close();
                                }else{
                                    Ext.Msg.alert('提示信息','请选择申报月份!');
                                }
                            }
                        },{
                            text:'重置',handler:function(){this.up('form').getForm().reset();}
                        },{
                            text:'关闭',handler:function(){dlg.close();}
                    }]
                })
             ]
         });
         dlg.show();
     }